package com.dgy.project.controller;

import java.util.List;

import com.dgy.project.pojo.dto.AssignExpertDTO;
import com.dgy.project.pojo.dto.ProjectAuditListDTO;
import com.dgy.project.pojo.vo.ProjectApplyListVO;
import com.dgy.project.pojo.vo.ProjectAuditListVO;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.dgy.project.domain.ProjectApplyAudit;
import com.dgy.project.service.IProjectApplyAuditService;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 项目专家评审Controller
 *
 * @author ccc
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/project/audit")
public class ProjectApplyAuditController extends BaseController
{
    @Autowired
    private IProjectApplyAuditService projectApplyAuditService;

    /**
     * 查询项目专家评审列表
     */
    @PreAuthorize("@ss.hasPermi('project:audit:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectApplyAudit projectApplyAudit)
    {
        startPage();
        List<ProjectApplyAudit> list = projectApplyAuditService.selectProjectApplyAuditList(projectApplyAudit);
        return getDataTable(list);
    }

    /**
     * 获取项目专家评审详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:audit:query')")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(projectApplyAuditService.selectProjectApplyAuditByReviewId(reviewId));
    }

    /**
     * 分配专家
     */
    @PreAuthorize("@ss.hasPermi('project:audit:assignExpert')")
    @Log(title = "项目专家评审", businessType = BusinessType.INSERT)
    @PostMapping("/assignExpert")
    public AjaxResult assignExpert(@RequestBody AssignExpertDTO assignExpertDTO)
    {
        return toAjax(projectApplyAuditService.assignExpert(assignExpertDTO));
    }

    /**
     * 修改项目专家评审
     */
    @PreAuthorize("@ss.hasPermi('project:audit:edit')")
    @Log(title = "项目专家评审", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectApplyAudit projectApplyAudit)
    {
        return toAjax(projectApplyAuditService.updateProjectApplyAudit(projectApplyAudit));
    }

    /**
     * 删除项目专家评审
     */
    @PreAuthorize("@ss.hasPermi('project:audit:remove')")
    @Log(title = "项目专家评审", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(projectApplyAuditService.deleteProjectApplyAuditByReviewIds(reviewIds));
    }


    /**
     * 我的评审
     */
    @PreAuthorize("@ss.hasPermi('project:audit:myAuditList')")
    @GetMapping("/myAuditList")
    public TableDataInfo myAuditList(ProjectAuditListDTO projectAuditListDTO)
    {
        startPage();
        // 当前用户信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        projectAuditListDTO.setExpertUserId(loginUser.getUserId());
        List<ProjectAuditListVO> list = projectApplyAuditService.selectMyAuditList(projectAuditListDTO);
        return getDataTable(list);
    }

    /**
     * 导出我的评审
     */
    @PreAuthorize("@ss.hasPermi('project:audit:exportMyAuditList')")
    @Log(title = "我的评审", businessType = BusinessType.EXPORT)
    @GetMapping("/exportMyAuditList")
    public void exportMyAuditList(HttpServletResponse response, ProjectAuditListDTO projectAuditListDTO)
    {
        // 当前用户信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        projectAuditListDTO.setExpertUserId(loginUser.getUserId());
        List<ProjectAuditListVO> list = projectApplyAuditService.selectMyAuditList(projectAuditListDTO);
        ExcelUtil<ProjectAuditListVO> util = new ExcelUtil<ProjectAuditListVO>(ProjectAuditListVO.class);
        util.exportExcel(response, list, "我的审核列表");
    }


}
